﻿/// <reference path="../Policy/apiSvc.js" />
/// <reference path="../Policy/editCtrl.js" />
/// <reference path="../Policy/listCtrl.js" />

/// <reference path="sharedSetup.js" />

describe("policy", function () {
    "use strict";
    runSharedSetup();

    var $httpBackend;
    beforeEach(inject(function (_$httpBackend_) {
        $httpBackend = _$httpBackend_;
    }));
    
    beforeEach(inject(function (_$httpBackend_) {
        $httpBackend.whenPOST('/api/policies/').respond({ "Value": getDto().Id, "Success": true, "ErrorMessage": null, "BrokenRules": [] });
    }));

    describe("editCtrl", function () {
        var scope;
        beforeEach(inject(function ($rootScope, $controller, $injector) {
            scope = $rootScope.$new();

            $controller("editCtrl", {
                $scope: scope
            });
        }));

        describe("on Save", function () {
            beforeEach(function () {
                spyOn(scope, '$emit');

                scope.item = getDto();
                scope.editForm = { $valid: true };
                scope.save();

                $httpBackend.expect("POST", "/api/policies/");
                $httpBackend.flush();
            });
            it("should Call a POST /api/policies/", function () {

            });

            it("should Emit itemAdded", function () {
                expect(scope.$emit).toHaveBeenCalledWith('itemAdded', getDto());
            });
        });
    });

    function getDto() {
        return { Id: 54, Number: 5555, PlateNo: "55YY", PersonID: 5 };
    }
});